package mvpexample.client.presenter;

import mvpexample.client.GreetingServiceAsync;
import mvpexample.client.view.AddOrderView;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PresenterImpl implements Presenter, AddOrderView.Presenter {

	private GreetingServiceAsync rpcService;

	private AddOrderView view;

	public PresenterImpl(GreetingServiceAsync rpcService, AddOrderView view) {
		this.rpcService = rpcService;
		this.view = view;
	}

	@Override
	public void onAddButtonClicked() {

		rpcService.greetServer(new AsyncCallback<String>() {
			public void onSuccess(String result) {
				view.setData(result);
			}

			public void onFailure(Throwable caught) {
				Window.alert("Error fetching contact details");
			}
		});
	}
}
